home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / ios.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  10.2 KB  |  455 lines

  1. #ifndef __STD_IOS__
  2. #define __STD_IOS__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * ios - Declarations for the Standard Library basic stream I/O
  8.  *
  9.  * $Id: ios,v 1.94 1996/09/24 19:17:05 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #ifndef __STD_RWCOMPILER_H__
  46. #include <stdcomp.h>
  47. #endif
  48.  
  49. // Get the locale class
  50. #include <rw/rwlocale>
  51.  
  52. // Get the facets
  53. #include <rw/ctype>
  54. #include <rw/codecvt>
  55. #include <rw/numeral>
  56.  
  57. // Get declarations for the standard xxx_byname facets and for vendor-defined
  58. // extensions, such as declarations of the facets of the native ("") locale.
  59. #include <rw/vendor>
  60.  
  61. // Get usefacet and hasfacet
  62. #include <rw/usefacet>
  63.  
  64.  
  65. #ifndef _RWSTD_NO_NAMESPACE
  66. namespace __rwstd {
  67. #endif
  68.  
  69. extern const char _RWSTDExportFunc(*) rwse_failbit_set;
  70. extern const char _RWSTDExportFunc(*) rwse_badbit_set;
  71. extern const char _RWSTDExportFunc(*) rwse_eofbit_set;
  72.  
  73. #ifndef _RWSTD_NO_NAMESPACE
  74. }
  75. namespace std {
  76. #endif
  77.  
  78. /*
  79.  *
  80.  *     CLASS BASIC_IOS
  81.  *
  82.  */
  83.  
  84. template<class charT, class traits>
  85. class _RWSTDExportTemplate basic_ios : public ios_base { 
  86.  
  87.       public:
  88.  
  89.             typedef basic_ios<charT, traits>           ios_type;
  90.             typedef basic_streambuf<charT, traits>     streambuf_type; 
  91.             typedef basic_ostream<charT, traits>       ostream_type;
  92.  
  93.               // simplification
  94.             typedef _TYPENAME traits::char_type      char_type;
  95.                 typedef traits                          traits_type;
  96.  
  97.             typedef _TYPENAME traits::int_type       int_type;
  98.             typedef _TYPENAME traits::off_type       off_type;
  99.             typedef _TYPENAME traits::pos_type       pos_type;
  100.     
  101.  
  102.             _EXPLICIT basic_ios(basic_streambuf<charT, traits> *sb_arg);
  103.          virtual ~basic_ios();
  104.  
  105.              char_type fill() const;        
  106.              char_type fill(char_type ch);
  107.  
  108.                 inline void exceptions(iostate excpt);
  109.             inline iostate exceptions() const;
  110.  
  111.                 inline void clear(iostate state = goodbit);
  112.  
  113.             inline void setstate(iostate state);
  114.                 inline iostate rdstate() const;
  115.  
  116.                 inline operator void*() const;
  117.                 inline bool operator! () const;
  118.  
  119.                 inline bool good() const;
  120.                 inline bool eof()  const;
  121.                 inline bool fail() const;
  122.                 inline bool bad()  const;
  123.  
  124.             ios_type& copyfmt(const ios_type& rhs);
  125.  
  126.             inline ostream_type *tie() const;
  127.             ostream_type *tie(ostream_type *tie_arg);
  128.  
  129.             inline streambuf_type *rdbuf() const;
  130.                 streambuf_type *rdbuf( streambuf_type *sb);
  131.  
  132.                 locale imbue(const locale& loc);
  133.  
  134.                 inline char  narrow(charT, char) const;
  135.                 inline charT widen(char) const;
  136.  
  137.       protected:
  138.  
  139.             basic_ios();
  140.  
  141.             void init(basic_streambuf<charT, traits> *sb);
  142.  
  143.                 inline void _RW_UNSAFE_clear(iostate state = goodbit);
  144.  
  145.       private:
  146.  
  147.             streambuf_type       *sb_;    
  148.  
  149.             ostream_type         *tiestr_;     
  150.  
  151.             char_type             fillch_; 
  152.  
  153.                 iostate            state_;   
  154.                 iostate            except_; 
  155.  
  156. };
  157.  
  158.  
  159. /*
  160.  *
  161.  *     INLINE DEFINITIONS
  162.  *
  163.  */
  164.  
  165.  
  166. /*
  167.  * basic_streambuf *rdbuf() const
  168.  */
  169.  
  170. template<class charT, class traits>
  171. inline basic_streambuf<charT, traits> *
  172. basic_ios<charT, traits>::rdbuf() const
  173. {
  174.   return sb_;
  175. }
  176.  
  177. /*
  178.  * basic_ostream *tie() const
  179.  */
  180.  
  181. template<class charT, class traits>
  182. inline basic_ostream<charT, traits> *
  183. basic_ios<charT, traits>::tie() const
  184. {
  185.   return tiestr_;
  186. }
  187.  
  188.  
  189. /*
  190.  * void exceptions(iostate)
  191.  */
  192.  
  193. template<class charT, class traits>
  194. inline void 
  195. basic_ios<charT, traits>::exceptions(ios_base::iostate st)
  196. {
  197.   #ifdef _RWSTD_MULTI_THREAD
  198.     _RWSTDGuard guard(this->stream_mutex_);
  199.   #endif
  200.  
  201.   except_ = st;
  202.  
  203.   #ifdef _RWSTD_MULTI_THREAD
  204.    _RW_UNSAFE_clear(rdstate()); 
  205.   #else
  206.    clear(rdstate());
  207.   #endif
  208. }
  209.  
  210. /*
  211.  * iostate exceptions() const
  212.  */
  213.  
  214. template<class charT, class traits>
  215. inline ios_base::iostate 
  216. basic_ios<charT, traits>::exceptions() const
  217.   return except_;
  218. }
  219.  
  220.  
  221. /*
  222.  * void clear(iostate )
  223.  */
  224.  
  225. template<class charT, class traits>
  226. inline void 
  227. basic_ios<charT, traits>::clear(iostate st)
  228. {
  229.   #ifdef _RWSTD_MULTI_THREAD
  230.     _RWSTDGuard guard(this->stream_mutex_);
  231.   #endif
  232.   
  233.   _RW_UNSAFE_clear(st); 
  234.  
  235. }
  236.  
  237. /*
  238.  * void setstate(iostate)
  239.  */
  240.  
  241. template<class charT, class traits>
  242. inline void
  243. basic_ios<charT, traits>::setstate(iostate st)
  244. {
  245.   #ifdef _RWSTD_MULTI_THREAD
  246.     _RWSTDGuard guard(this->stream_mutex_);
  247.   #endif
  248.  
  249.   #ifdef _RWSTD_MULTI_THREAD
  250.    _RW_UNSAFE_clear(state_ | st); 
  251.   #else
  252.    clear(state_ | st);
  253.   #endif
  254. }
  255.  
  256. /*
  257.  * iostate rdstate() const
  258.  */
  259.  
  260. template<class charT, class traits>
  261. inline ios_base::iostate 
  262. basic_ios<charT, traits>::rdstate() const
  263. {
  264.   return state_;
  265. }
  266.  
  267. /*
  268.  * operator bool() const
  269.  */
  270.  
  271. template<class charT, class traits>
  272. inline basic_ios<charT, traits>::operator void*() const
  273. {
  274.   return fail() ? (void*)0 : (void*)1;
  275. }
  276.  
  277. /*
  278.  * bool operator!() const
  279.  */
  280.  
  281. template<class charT, class traits>
  282. inline bool 
  283. basic_ios<charT, traits>::operator!() const
  284. {
  285.   return fail();
  286. }
  287.  
  288. /*
  289.  * bool good() const
  290.  */
  291.  
  292. template<class charT, class traits>
  293. inline bool 
  294. basic_ios<charT, traits>::good() const
  295. {
  296.   return (state_ == ios_base::goodbit);
  297. }
  298.  
  299. /*
  300.  * bool eof() const
  301.  */
  302.  
  303. template<class charT, class traits>
  304. inline bool 
  305. basic_ios<charT, traits>::eof() const
  306. {
  307.   return (state_ & ios_base::eofbit);
  308. }
  309.  
  310. /*
  311.  * bool fail() const
  312.  */
  313.  
  314. template<class charT, class traits>
  315. inline bool 
  316. basic_ios<charT, traits>::fail() const
  317. {
  318.   return (state_ & (ios_base::failbit | ios_base::badbit));
  319. }
  320.  
  321. /*
  322.  * bool bad() const
  323.  */
  324.  
  325. template<class charT, class traits>
  326. inline bool 
  327. basic_ios<charT, traits>::bad() const
  328. {
  329.   return (state_ & ios_base::badbit);
  330. }
  331.  
  332. /*
  333.  * void _RW_UNSAFE_clear(iostate )
  334.  */
  335.  
  336. template<class charT, class traits>
  337. inline void 
  338. basic_ios<charT, traits>::_RW_UNSAFE_clear(iostate st)
  339. {
  340.   if ( !sb_ ) 
  341.   {
  342.     st |= ios_base::badbit;
  343.     state_ |= ios_base::badbit; 
  344.   }
  345.  
  346.   state_ = st;
  347.  
  348.   if( rdstate() & exceptions() )
  349.  {
  350. #ifdef _RW_STD_EXCEPT
  351. #ifndef _RWSTD_NO_EXCEPTIONS
  352.  if ( rdstate() & exceptions() & ios_base::failbit )
  353.     { 
  354.       state_=st;
  355.       throw ios_base::failure( string(__RWSTD::rwse_failbit_set) );
  356.     }
  357.  
  358.   if ( rdstate() & exceptions() & ios_base::badbit )
  359.     { 
  360.       state_=st;
  361.       throw ios_base::failure( string(__RWSTD::rwse_badbit_set) );
  362.     }
  363.  if ( rdstate() & exceptions() & ios_base::eofbit )
  364.     { 
  365.       state_=st;
  366.       throw ios_base::failure( string(__RWSTD::rwse_eofbit_set) );
  367.     }
  368. #endif
  369. #endif    
  370.   }
  371. }
  372.  
  373. /*
  374.  * char narrow(charT, char) const
  375.  */
  376.  
  377. template<class charT, class traits>
  378. inline char 
  379. basic_ios<charT, traits>::narrow(charT c, char dfault) const
  380. {
  381.    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  382.      return use_facet< ctype<charT> >(getloc()).narrow(c.dfault);
  383.    #else
  384.      return use_facet(getloc(),(ctype<charT>*)0).narrow(c,dfault);
  385.    #endif
  386.      
  387. }
  388.  
  389. /*
  390.  * charT widen(char) const
  391.  */
  392.  
  393. template<class charT, class traits>
  394. inline charT 
  395. basic_ios<charT, traits>::widen(char c) const
  396. {
  397.    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  398.      return use_facet< ctype<charT> >(getloc()).widen(c);
  399.    #else
  400.      return use_facet(getloc(),(ctype<charT>*)0).widen(c);
  401.    #endif
  402.      
  403. }
  404.  
  405.  
  406. // end inlining
  407.  
  408.  
  409. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  410.     typedef basic_ios<char>                   ios;
  411. #else
  412.     typedef basic_ios<char, char_traits<char> >      ios;
  413. #endif
  414.  
  415. #ifndef _RWSTD_NO_WIDE_CHAR
  416.     #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  417.         typedef basic_ios<wchar_t>              wios;
  418.     #else
  419.         typedef basic_ios<wchar_t, char_traits<wchar_t> >  wios;
  420.     #endif
  421. #endif
  422.  
  423. /*
  424.  *
  425.  *     EXTERNAL DECLARATIONS FOR MANIPULATORS
  426.  *
  427.  */
  428.  
  429.  
  430. #ifdef _RWSTD_MULTI_THREAD
  431.   template <class charT, class traits>
  432.   basic_ios<charT,traits>& lock(basic_ios<charT,traits>&);
  433.  
  434.   template <class charT, class traits>
  435.   basic_ios<charT,traits>& unlock(basic_ios<charT,traits>&);
  436. #endif
  437.  
  438.  
  439.  
  440. #ifndef _RWSTD_NO_NAMESPACE
  441. }
  442. #endif
  443.  
  444. #ifdef _RWSTD_COMPILE_INSTANTIATE
  445.     #include <ios.cc>
  446. #endif
  447.  
  448. #ifndef __USE_STD_NAMES__
  449.   using namespace std;
  450. #endif
  451.  
  452. #pragma option pop
  453. #endif /* __STD_IOS__ */
  454.